﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Include_UseControl_AdminLeft : System.Web.UI.UserControl
{
    public int RootID
    {
        get { return DongDong.Common.Misc.ConvertToInt(ViewState["_RootID"]); }
        set { ViewState["_RootID"] = value; }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminUser objAdminUser = AdminUser.GetCurrent();
        if (!IsPostBack && objAdminUser != null)
        {
            RootID = DongDong.Common.Misc.GetQueryStringAsInt("RootID");
            PopulateNava();
        }
    }


    public void PopulateNava()
    {
        AdminUser objAdminUser = AdminUser.GetCurrent();
        if (RootID == 0)
        {
            string URL = HttpContext.Current.Request.Path.ToString();
            Navigation objNava = Navigation.GetByURL(URL);
            if (objNava != null)
                RootID = objNava.RootID;
        }


        if (RootID == 0)
        {
            Navigation objNavigation = Navigation.GetAllRootNavaByAdminRoleID(objAdminUser.RoleID).FirstOrDefault();
            if (objNavigation != null)
            {
                RootID = objNavigation.ID;
            }
        }
        rptNava.DataSource = Navigation.GetAllParNavaByAdminRoleID_ParentID(objAdminUser.RoleID, RootID);
        rptNava.DataBind();
    }

    protected void rptNava_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            AdminUser objAdminUser = AdminUser.GetCurrent();
            HiddenField hdlID = (HiddenField)e.Item.FindControl("hdlID");
            Repeater rptChildNava = (Repeater)e.Item.FindControl("rptChildNava");
            rptChildNava.DataSource = Navigation.GetAllNavaByAdminRoleID_ParentID(objAdminUser.RoleID, DongDong.Common.Misc.ConvertToInt(hdlID.Value));
            rptChildNava.DataBind();
        }
    }
}